<script>
	import {
		api_root,
		get,
		post,
		axios,
		uploadFile,
		getAuthCode,
		doLogin
	} from './utils/request.js'
	import {
		throttle,
		debounce
	} from '@/utils/index.js'
	const typeList = [{
		name: '商城',
		type: 'sc',
		value: true,
	}, {
		name: '租赁',
		type: 'zl',
		value: false,
	}, ]
	const appTypeList = [{
		name: '小程序',
		type: 'mp',
	}, {
		name: 'H5',
		type: 'web',
	}, {
		name: 'App',
		type: 'app',
	}, {
		name: '微信',
		type: 'mp-weixin',
	}, {
		name: '支付宝',
		type: 'mp-alipay',
		openType: 'getAuthorize',
	}, {
		name: '抖音',
		type: 'mp-toutiao',
		openType: 'getPhoneNumber',
	}, ]
	const addressList = ['mp-weixin', 'mp-alipay']
	const vibrateList = ['mp-weixin', 'mp-alipay']
	const loginList = ['mp-weixin', 'mp-alipay', 'mp-toutiao']
	const updateList = ['mp-weixin', 'mp-alipay', 'mp-toutiao']
	const mpList = ['mp-weixin', 'mp-alipay', 'mp-toutiao']
	const phoneList = ['mp-weixin', 'mp-alipay', 'mp-toutiao']
	const userInfoList = ['mp-weixin', 'mp-toutiao']
	export default {
		globalData: {
			api_root,
			type: typeList[1].value,
			appType: 'web',
			appTypeList,
			addressList,
			vibrateList,
			loginList,
			mpList,
			phoneList,
			userInfoList,
			primaryColor: '#f39066'
		},
		onLaunch: function(options) {
			console.log(options)
			if(options&&options.query&&options.query.store_id){
				let store_id = options.query.store_id
				uni.setStorageSync('store_id',store_id)
			}
			const appType = this.getAppType()
			this.globalData.appType = appType
			this.updateManager()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			get,
			post,
			axios,
			uploadFile,
			getAuthCode,
			doLogin,
			throttle,
			debounce,
			updateManager() {
				console.log(this.globalData.appType, '客户端')
				if (updateList.find(p => p == this.globalData.appType)) {
					const updateManager = uni.getUpdateManager();
					updateManager.onUpdateReady(function(res) {
						uni.showModal({
							title: '更新提示',
							content: '新版本已经准备好，是否重启应用？',
							success(res) {
								if (res.confirm) {
									updateManager.applyUpdate();
								}
							}
						});
					});
				}
			},
			getAppType() {
				// const { platform } = uni.$uv
				// ['weixin','alipay','toutiao','h5']
				const {
					uniPlatform
				} = uni.getSystemInfoSync()
				return uniPlatform
			},
			vibrate() {
				if (vibrateList.find(p => p == this.globalData.appType)) {
					uni.vibrateShort()
				}
			},

			removeCurrencySymbolAndConvertToNumber(str) {
				// 使用正则表达式移除所有非数字字符（除了小数点）  
				const cleanStr = str.replace(/[^\d.]/g, '');
				// 将清理后的字符串转换为浮点数  
				const num = parseFloat(cleanStr);
				return num;
			},
			callPhone() {
				uni.showLoading()
				const phoneNumber = uni.getStorageSync('phoneNumber');
				if (phoneNumber) {
					uni.makePhoneCall({
						phoneNumber,
						complete: () => {
							uni.hideLoading()
						}
					});
				} else {
					uni.showToast({
						icon: 'fail',
						title: '客服电话为空',
						duration: 2000,
						complete: () => {
							uni.hideLoading()
						}
					})
				}
			},
			downloadFile(url) {
				uni.downloadFile({
					url: url,
					success(res) {
						console.log(res, '下载')
						uni.openDocument({
							filePath: res.tempFilePath,
							fileType: "pdf"
						});
					}
				});
			},
			checkH5Login() {
				let userInfo = uni.getStorageSync("userInfo");
				let isH5 = false
				// #ifdef H5
				isH5 = true
				// #endif
				if (isH5 && !userInfo) {
					uni.showModal({
						content: "您还没有登录,请先登录",
						confirmText: "去登陆",
						cancelText: "取消",
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/login/login'
								})
							}
						}
					});
					console.log('您还没有登录,请先登录')
					return false;
				}
				return true;
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css
html{
	height: auto;
} */
	body,
	page,
	#app {
		font-size: 16px;
		background-color: whitesmoke;
		//height: max-content;
		//height: -webkit-fill-available;
		font-family: "楷体";
	}

	uni-page-body {
		height: 100%;
	}

	:root,
	page {
		--primary-color: #f39066;
		--nut-grid-item-content-padding: 6px 0;
		--nut-tabs-titles-border-radius: 10px;
		--nut-cell-padding: 10px;
		--nut-radio-label-margin-left: 4px;
		--nut-cell-desc-color: black;
		--nut-sku-product-img-width: 70px;
	}

	.uv-empty {
		.uv-icon {
			margin-top: 20%
		}
	}

	input,
	textarea {
		background-color: inherit !important;
	}

	.w-full {
		width: 100%;
	}

	.h-full {
		height: 100%;
	}

	.wh-full {
		width: 100%;
		height: 100%;
	}

	.w-fill {
		width: -webkit-fill-available;
	}

	.h-fill {
		height: -webkit-fill-available;
	}

	.p-10 {
		padding: 10px;
	}

	.m-10 {
		margin: 10px;
	}

	.g-4 {
		gap: 4px;
	}

	.content {
		&>view {
			width: -webkit-fill-available;
		}
	}

	.ellipsis {
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;
	}

	.nowrap {
		white-space: nowrap;
	}

	.uv-search__content {
		border-radius: $uni-border-radius-lg !important;
	}

	.uv-checkbox-group--row {
		align-items: center;
	}

	.uni-toast__content {
		font-size: small;
	}

	.uni-modal {
		transition: all .25s ease;
		border-radius: 20px;
	}

	.nut-grid {
		background-color: white;
		padding: 2px;
	}

	.nut-grid-item {
		transition: all 0.3s ease-out;

		&:active {
			transform: scale(0.98);
			box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.1);
		}
	}

	.uv-notice-bar .uv-notice__content__text {
		animation-duration: 20s !important;
	}

	.active,
	.actived {
		transition: all 0.3s ease-out;

		&:active {
			transform: scale(0.98);
		}
	}

	.nut-tabs {
		width: -webkit-fill-available;
	}

	.nut-tabs {
		height: 100%;
	}

	.tabs,
	.grid,
	.card,
	.border,
	.nut-textarea {
		border-radius: $uni-border-radius-lg;
	}

	.nut-textarea {
		.nut-textarea__textarea {
			width: 90% !important;
		}
	}

	.nut-button,
	.nut-sku-content,
	.uni-scroll-view {
		width: -webkit-fill-available !important;
	}

	.nut-sku-content {
		padding: 0 0 0 18px !important;
		margin-top: 10px !important;

		.uni-scroll-view:first {
			padding-right: 18px;
		}

		.nut-sku-stepper {
			padding-bottom: 10px;
			margin: auto !important;
		}
	}

	.nut-avatar {
		background-color: transparent !important;
	}

	.nut-toast {
		z-index: 999 !important;
		background-color: transparent !important;
	}

	.nut-overlay {
		border-radius: 0 !important;
	}

	.nutSlideUpIn {
		position: fixed;
		bottom: 0;
		width: 100%;
		background-color: white;
		border-radius: 20px 20px 0 0 !important;
		padding-bottom: env(safe-area-inset-bottom);

		.nut-sku {
			border-radius: 20px 20px 0 0;
		}
	}

	.nutFadeIn {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		background-color: #00000091;
		opacity: 0.5;
		overflow: hidden;
	}

	.nut-image-preview {
		background-color: black;
	}

	.nut-address-list {
		padding-bottom: 0 !important;
		display: grid;
		gap: 10px;

		.nut-address-list-general {
			border-radius: $uni-border-radius-lg;
		}
	}

	.nut-form-item {
		border-radius: var(--nut-cell-border-radius, 6px);

		.nut-input,
		.nut-textarea {
			padding: 0 !important;
			margin: 0 !important;
			line-height: var(--nut-cell-line-height) !important;
			border-bottom: none !important;
		}
	}

	.nut-form-item__label {
		font-weight: bolder;
	}

	.nut-form-item::before {
		bottom: 10px !important;
		line-height: normal;
	}

	.nut-address-list-item__info-handle-edit {
		display: none !important; //隐藏地址编辑
	}

	.uni-toast {
		background: rgba(255, 255, 255, .05);
		box-shadow: 0 0 10px rgba(0, 0, 0, 0.25);
		backdrop-filter: blur(10px);
		color: initial;
	}

	.ease-out {
		transition: all 0.3s ease-out;
	}

	.btn,
	.nut-address-list__bottom {
		width: -webkit-fill-available !important;
		border-radius: 40px !important;
		position: fixed;
		padding: 10px !important;
		margin: 4px;
		bottom: env(safe-area-inset-bottom);
		background: rgba(255, 255, 255, .05);
		box-shadow: 0 0 10px rgba(0, 0, 0, 0.25);
		backdrop-filter: blur(10px);
		display: flex;
		flex-flow: column;
		transition: all 0.3s ease-out;

		&:active {
			transform: scale(0.98);
			box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.1);
		}
	}

	.space-between {
		display: flex;
		justify-content: space-between;
		width: -webkit-fill-available;
	}

	.space-around {
		display: flex;
		justify-content: space-around;
		width: -webkit-fill-available;
	}

	.relative {
		position: relative;
	}

	.absolute {
		position: absolute;
	}

	.flex {
		display: flex;
	}

	.column {
		display: flex;
		flex-direction: column;
	}

	.box {
		background-color: white;
		border-radius: $uni-border-radius-lg;
	}

	.blur {
		background: rgba(255, 255, 255, 0.25);
		box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
		backdrop-filter: blur(4px);
		-webkit-backdrop-filter: blur(4px);
		border-radius: 10px;
		border: 1px solid rgba(255, 255, 255, 0.18);
	}

	.sticky {
		position: sticky;
		top: -1px;
		z-index: 999;
	}
</style>
<style lang="scss">
	@import '@climblee/uv-ui/index.scss';
</style>